//
//  YZLHeaderCell.m
//  Car
//
//  Created by dllo on 15/11/10.
//  Copyright © 2015年 岳明. All rights reserved.
//

#import "YZLHeaderCell.h"
#import "YZLSeriesListModel.h"
#import <UIImageView+WebCache.h>
#import "Macro.h"

@interface YZLHeaderCell ()

@property (nonatomic, strong) UIImageView *leftImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *guideLabel;
@property (nonatomic, strong) UILabel *priceLabel;

@end

@implementation YZLHeaderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        self.leftImageView = [[UIImageView alloc] init];
        [self addSubview:self.leftImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        [self addSubview:self.titleLabel];
        
        self.guideLabel = [[UILabel alloc] init];
        self.guideLabel.textColor = [UIColor grayColor];
        self.guideLabel.font = [UIFont systemFontOfSize:15];
        [self addSubview:self.guideLabel];
        
        self.priceLabel = [[UILabel alloc] init];
        self.priceLabel.textColor = [UIColor orangeColor];
        self.priceLabel.font = [UIFont systemFontOfSize:15];
        [self addSubview:self.priceLabel];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.leftImageView.frame = CGRectMake(15, 5, (kWidth - 30) / 4, self.frame.size.height - 10);
    self.titleLabel.frame = CGRectMake(20 + self.leftImageView.frame.size.width, 5, kWidth - 20 - self.leftImageView.frame.size.width, (self.frame.size.height - 10 ) / 2);
    self.guideLabel.frame = CGRectMake(20 + self.leftImageView.frame.size.width, 5 + self.titleLabel.frame.size.height, self.leftImageView.frame.size.width * 3 / 4, (self.frame.size.height - 10 ) / 2);
    self.priceLabel.frame = CGRectMake(30 + self.leftImageView.frame.size.width + self.guideLabel.frame.size.width, 5 + self.titleLabel.frame.size.height, kWidth - 30 - self.leftImageView.frame.size.width + self.guideLabel.frame.size.width, (self.frame.size.height - 10 ) / 2);
}

- (void)setModel:(YZLSeriesListModel *)model {
    if (_model != model) {
        _model = model;
    }
    [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.seriesImage] placeholderImage:[UIImage imageNamed:@"D0"]];
    
    
    self.guideLabel.text = @"指导价：";
    self.priceLabel.text = model.guidePrice;
}

- (void)setSearchString:(NSString *)searchString {
    if (_searchString != searchString) {
        _searchString = searchString;
    }
    NSString *title = [[_model.seriesName stringByReplacingOccurrencesOfString:@"<font color=\"red\">" withString:@""] stringByReplacingOccurrencesOfString:@"</font>" withString:@""];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:title];
    NSRange range = [title rangeOfString:self.searchString];
    
    [attributedString setAttributes:@{NSForegroundColorAttributeName:[UIColor redColor], NSFontAttributeName:[UIFont systemFontOfSize:17]} range:range];
    
    self.titleLabel.attributedText = attributedString;
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
